package labox.innovation.gameserver.network.clientpackets;

import labox.innovation.gameserver.model.L2Object;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

/**
 * 客户端请求攻击
 * 
 * @version $Revision: 1.7.2.1.2.2 $ $Date: 2005/03/27 15:29:30 $
 */
public final class AttackRequest extends L2GameClientPacket {

	private long _objectId;

	private static final String _C__50_ATTACKREQUEST = "[C] 50 AttackRequest";

	@Override
	protected void readImpl() {
		_objectId = readLong();
	}

	@Override
	protected void runImpl() {
		final FuzePcInstance activeChar = getClient().getActiveChar();
		if (activeChar == null)
			return;
		// avoid using expensive operations if not needed
		final L2Object target;

		target = activeChar.getKnownList().getKnownCharacters().get(_objectId);

		if (target == null)
			return;

		// Players can't attack objects in the other instances except from multiverse
		if (target.getInstanceId() != activeChar.getInstanceId() && activeChar.getInstanceId() != -1)
			return;

		//如果角色发生了攻击逻辑直接结束出生保护
		if(activeChar.isSpawnProtected())
			activeChar.onActionRequest();
		target.onAction(activeChar);
	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.clientpackets.ClientBasePacket#getType()
	 */
	@Override
	public String getType() {
		return _C__50_ATTACKREQUEST;
	}

}
